package boundary;

import java.awt.GridBagLayout;

import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.ListModel;

import java.awt.GridBagConstraints;
import java.awt.Font;
import javax.swing.JList;

import store.Ricetta;

import dataview.RicettaVisCorta;
import dataview.Ricette;
import java.awt.Insets;

public class AccedereRicette extends JPanel {

	private static final long serialVersionUID = 1L;
	private Ricette ultimeCercate;
	private JLabel titoloLabel = null;
	private JList jList = null;
	private DefaultListModel model;

	/**
	 * This is the default constructor
	 */
	public AccedereRicette(Ricette ultimeCercate) {
		super();
		this.ultimeCercate=ultimeCercate;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.fill = GridBagConstraints.BOTH;
		gridBagConstraints1.gridy = 1;
		gridBagConstraints1.weightx = 1.0;
		gridBagConstraints1.weighty = 1.0;
		gridBagConstraints1.insets = new Insets(5, 0, 0, 0);
		gridBagConstraints1.gridx = 0;
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.insets = new Insets(5, 0, 0, 0);
		gridBagConstraints.gridy = 0;
		titoloLabel = new JLabel();
		titoloLabel.setText("Ricerche recenti");
		titoloLabel.setFont(new Font("Dialog", Font.BOLD, 20));
		this.setSize(300, 200);
		this.setLayout(new GridBagLayout());
		this.add(titoloLabel, gridBagConstraints);
		this.add(getJList(), gridBagConstraints1);
	}

	/**
	 * This method initializes jList	
	 * 	
	 * @return javax.swing.JList	
	 */
	private JList getJList() {
		if (jList == null) {
			model = new DefaultListModel();
			if (ultimeCercate == null || ultimeCercate.size() < 1)
				model.addElement("Nessuna ricetta cercata recentemente");
			else {
				for (Ricetta r : ultimeCercate)
					model.addElement(r.getNome()+" "+r.getInfo());
			}
			jList = new JList(model);
			jList.setFont(new Font("Georgia", Font.PLAIN, 12));
		}
		return jList;
	}

}
